package com.youlu.campus.web.feedback.controller;

import com.youlu.campus.web.common.base.RequestContext;
import com.youlu.campus.web.feedback.dto.FeedBackCreateRequest;
import com.youlu.campus.web.feedback.entity.FeedBackInfo;
import com.youlu.campus.web.feedback.service.FeedBackService;
import com.yuelin.infrastructure.quantum.common.QResult;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 问题反馈相关接口
 */
@RestController
public class FeedBackController {
    @Autowired
    private FeedBackService feedBackService;

    /**
     * 问题反馈
     * 备注：新增反馈信息
     * 参数：request - 问题反馈创建请求类
     * 返回：200-请求成功，返回Boolean类型结果（表示操作是否成功）
     */
    @PostMapping("/mini-app/feed-back/create")
    public QResult create(@RequestBody @Valid FeedBackCreateRequest request) {
        FeedBackInfo f = new FeedBackInfo();
        BeanUtils.copyProperties(request, f);
        f.setUserId(RequestContext.getUserId());
        return QResult.success(feedBackService.create(f, RequestContext.getCurUser()));
    }

    /**
     * 简版问题反馈
     * 备注：新增简版反馈信息
     * 参数：request - 问题反馈创建请求类
     * 返回：200-请求成功，返回Boolean类型结果（表示操作是否成功）
     */
    @PostMapping("/mini-app/feed-back/mini-create")
    public QResult miniCreate(@RequestBody @Valid FeedBackCreateRequest request) {
        FeedBackInfo f = new FeedBackInfo();
        BeanUtils.copyProperties(request, f);
        f.setUserId(RequestContext.getUserId());
        return QResult.success(feedBackService.miniCreate(f, RequestContext.getCurUser()));
    }
}